// 
//  MainWindow.cs
//  
//  Author:
//       Krzysztof Marecki 
// 
//  Copyright (c) 2010 Krzysztof Marecki
// 
//  This file is part of the NReports project
//	
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

using System;
using Gtk;

namespace NReports.GtkReportViewer
{
	public partial class MainWindow : Gtk.Window
	{
		public MainWindow () : base(Gtk.WindowType.Toplevel)
		{
			Build ();
			reportviewer.ShowParameters = true;
		}
	
		protected void OnDeleteEvent (object sender, DeleteEventArgs a)
		{
			Application.Quit ();
			a.RetVal = true;
		}
		
		protected virtual void OnQuitActionActivated (object sender, System.EventArgs e)
		{
			Destroy ();
		}
		
		protected virtual void OnOpenActionActivated (object sender, System.EventArgs e)
		{
			FileChooserDialog dlg = new FileChooserDialog ("Open RDL report", 
			                                                      this, 
			                                                      FileChooserAction.Open,
			                                                      Stock.Cancel, ResponseType.Cancel,
			                                                      Stock.Open, ResponseType.Ok);
			try {
				dlg.SelectMultiple = false;
				
				FileFilter filter = new FileFilter ();
				filter.Name = "Report files (*.rdl | *.rdlc)";
				filter.AddPattern ("*.rdl");
				filter.AddPattern ("*.rdlc");
				dlg.AddFilter (filter);
				
				FileFilter filter2 = new FileFilter ();
				filter2.Name = "All files (*.*)";
				filter2.AddPattern ("*.*");
				dlg.AddFilter (filter2);
				
				if (dlg.Run () == (int)ResponseType.Ok) {
				
					reportviewer.LoadReport (dlg.Filename);
				}
			} finally {
				
				dlg.Destroy ();
			}
		}
		protected virtual void OnAboutActionActivated (object sender, System.EventArgs e)
		{
			using (AboutDialog dlg = new AboutDialog ()) {
				dlg.Authors = new string[] {"Krzysztof Marecki"};
				dlg.Copyright = "(C) 2010-2011 by Krzysztof Marecki";
				dlg.ProgramName = "NReports Viewer 0.8.1";
				dlg.Run();
				dlg.HideAll();
			}
		}
	}
}
